﻿using Microsoft.Extensions.DependencyInjection;
using Quartz;
using Quartz.Spi;
using Sprout.Core;
using System;
using System.Collections.Generic;
using System.Text;

namespace Sprout.Schedule.Services
{
    /// <summary>
    /// 实现 job DI注入方式获得
    /// </summary>
    public class JobFactory : IJobFactory
    {
        public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler)
        {
            return (IJob)ServiceLocator.GetService(bundle.JobDetail.JobType);
        }

        public void ReturnJob(IJob job)
        {
            var disposable = job as IDisposable;
            disposable?.Dispose();
        }
    }
}
